@extends('admin.index')
@section('name')
    <h1><span class="label label-default"> 公告管理  </span></h1>
    <hr>

    <table class="table table-bordered  table-hover" id="tent">
        <tr >
            <th>ID</th>
            <th>公告内容</th>
            <th>链接地址</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        @foreach($res as $list)
            <tr id="nei">
                <th scope="row">{{$list->id}}</th>
                <th>{{$list->ann_cont}}</th>
                <th>{{$list->ann_url}}</th>
                <th id="ths">
                    @if(($list->display) == 1)

                        <a href="{{url('adm/ann/edit')}}/{{$list->id}}/{{$list->display}}" class="btn btn-info">显示</a>

                    @else
                        <a href="{{url('adm/ann/edit')}}/{{$list->id}}/{{$list->display}}" class="btn btn-success">禁用</a>

                    @endif

                </th>

                <th>

                    <button class="btn btn-danger" onclick="del({{$list->id}})" id="but1">删除</button>




                    {{--模态框--}}

                    <button type="button" onclick="edi({{$list->id}})" class="btn btn btn-info" data-toggle="modal" data-target="#myModal" id="bbb">
                        编辑
                    </button>


                    <!-- Modal -->
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h1><span class="label label-default"> 公告修改  </span></h1>
                                </div>
                                <div class="modal-body" style="marigin-leift:20px">

             <form action="{{url('adm/ann/update')}}">

                                        <p>内容: <input required type="text" name='ann_cont' placeholder='cont' id="na" value=""></p>

                                        <p>Url:<input type="text" name='ann_url' value="" id="url">

                                            <input type="hidden" id="nid" name="id" value="">

                                        </p>

                                        <p>Display:
                                            <label for="y"> <input  id='y' type="radio" name='display' value="1" > 显示 </label>
                                            <label for="n"> <input  id='n' type="radio" name='display' value="2" > 隐藏 </label>



                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">退出</button>
                                    <button type="submit" class="btn btn-primary">保存</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>

                    {{--end  motai--}}





                </th>
            </tr>
            @endforeach
    </table>





    {{$res->links()}}

    <script>


        function edi(a)
        {
            var data = a;

            $.ajax({
                type:'get',
                url:"{{url('adm/ann/edit')}}/" + data,

                success:function(data){
                    if(data){

                        $('#nid').attr("value",data[0]);

                        console.log(data[0])
                        $('#na').attr("value",data[1]);
                        $('#url').attr("value",data[2]);

                        if (data[3] == 1)

                        $('#y').attr('checked','checked');

                    }if(data[3] == 2){

                        $('#n').attr('checked','checked');
                    }

                    console.log(data);
                },
                error:function(){

                    console.log('错误');
                }
            })
        }




        function del(b) {

            if (confirm('你确定要删除嘛')) {

                var data = b;

                $.ajax({
                type:'get',
                url:"{{url('adm/ann/del')}}/" + data,
                success:function(data){

                        if (data == 1) {

                        $('#but1').parent().parent().remove();

                        }

                    console.log(data);
                        },
                error:function(){

                        console.log('错误');

                        alert('ajax  错误');
                        }
                })

                }else{

                alert('点错了吧QAQ');

                }

            }




    </script>



@endsection
